From 4e3d9f20b7106f12c576eeb402da2b29c660a414 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 3 Oct 2023 15:37:59 +0700
Subject: bugfix widget wa di page variant detail

---
 src/pages/shop/product/variant/[slug].jsx | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

(limited to 'src/pages/shop/product/variant/[slug].jsx')

diff --git a/src/pages/shop/product/variant/[slug].jsx b/src/pages/shop/product/variant/[slug].jsx
index d0790249..401bce82 100644
--- a/src/pages/shop/product/variant/[slug].jsx
+++ b/src/pages/shop/product/variant/[slug].jsx
@@ -7,6 +7,8 @@ import { useRouter } from 'next/router'
 import cookie from 'cookie'
 import variantApi from '@/lib/product/api/variantApi'
 import axios from 'axios'
+import { useProductContext } from '@/contexts/ProductContext'
+import { useEffect } from 'react'
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
 const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
@@ -19,16 +21,18 @@ export async function getServerSideProps(context) {
   const tier = auth.pricelist ? auth.pricelist : false
   const authToken = auth?.token || ''
 
-
   let response = await axios(
-    `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=` + getIdFromSlug(slug) +'&auth=' + tier
+    `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=` +
+      getIdFromSlug(slug) +
+      '&auth=' +
+      tier
   )
   let product = response.data
   // let product = await variantApi({ id: getIdFromSlug(slug), headers: { Token: authToken } })
-  
+
   if (product?.length == 1) {
     product = product[0]
-   /* const regexHtmlTags = /(<([^>]+)>)/gi
+    /* const regexHtmlTags = /(<([^>]+)>)/gi
     const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
     product.description = product.description
       .replace(regexHtmlTagsExceptP, ' ')
@@ -46,6 +50,14 @@ export async function getServerSideProps(context) {
 export default function ProductDetail({ product }) {
   const router = useRouter()
 
+  const { setProduct } = useProductContext()
+
+  useEffect(() => {
+    if (product) {
+      setProduct(product)
+    }
+  }, [product, setProduct])
+
   if (!product) return <PageNotFound />
 
   return (
-- 
cgit v1.2.3

